package com.yunao.service.report.esou;

import com.yunao.commons.serachcore.core.bean.Cube;
import com.yunao.commons.serachcore.core.bean.Cubes;
import com.yunao.commons.serachcore.core.bean.Group;
import com.yunao.commons.serachcore.core.bean.Groups;
import com.yunao.service.report.bean.GroupBean;
import com.yunao.service.report.esou.Jfreechart.BarChart;
import com.yunao.service.report.esou.Jfreechart.LineChart;
import com.yunao.service.report.esou.common.Profile;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.TextAnchor;

import java.awt.*;
import java.io.File;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class JFreeChartUtil {
	
	public final static String[] emotion = new String[] {    "正面" , "负面","中性" };
	/**
	 * 横坐标为 long 型时间
	 * 
	 * @param beans
	 *            结果
	 * @param title
	 *            图表标题
	 * @return 图表位置
	 * @throws Exception
	 */
	public static String drawLine(Cubes beans, String title, String filePath) throws Exception {
		// 排序
		beans.sortByKey();
		int len = beans.size();
		// x 轴
		
		String[] xAxis = new String[len];
		String format;
		try {
			long t1 = Long.parseLong(beans.get(0).getKey()+"000");
			long t2 = Long.parseLong(beans.get(1).getKey()+"000");
			if ((t1 - t2) < 24 * 60 * 60 * 1000l)
				format = "d-H";
			else
				format = (beans.size() > 10) ? "M-d" : "yyyy-M-d";
		} catch (Exception e) {
			format = "yyyy-M-d";
		}
		int m =0;
		SimpleDateFormat dateFormat = new SimpleDateFormat(format);
		String[] row = new String[] { "其他","新闻" , "论坛" , "博客" , "微博" , "微信" , "政务" 
				, "客户端" , "电子报" , "贴吧" , "视频" , "电视"};
		double[] qbArray = new double[len],wxArray = new double[len] , wbArray = new double [len] , ltArray = new double [len] 
				, xwArray = new double [len] , bkArray = new double [len] , zwArray = new double [len]
				, khdArray = new double [len] , dzbArray = new double [len] , tbArray = new double [len]
				, spArray = new double [len] , dsArray = new double [len] ;
		for (int i = len - 1; i >= 0; i--) {
			int wx = 0 , wb = 0 , lt = 0 , xw = 0 , bk = 0 ,zw = 0 , khd = 0 , dzb = 0 , tb = 0 
					, sp = 0 , ds = 0,qb = 0;
			Cube cubeBean = beans.get(i);
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
			Date parse = simpleDateFormat.parse(cubeBean.getKey());
			long long1 = parse.getTime();

			xAxis[m] = dateFormat.format(new Date(long1));
			
			for (int j = 0; j < cubeBean.getSubs().size(); j++) {
				Group sub = cubeBean.getSubs().get(j);
				switch (sub.getKey()) {
					case "新闻":xw = (int)sub.getValue() ;break;
					case "论坛":lt = (int)sub.getValue() ;break;
					case "博客":bk = (int)sub.getValue() ;break;
					case "微博":wb = (int)sub.getValue() ;break;
					case "微信":wx = (int)sub.getValue() ;break;
					case "政务":zw = (int)sub.getValue() ;break;
					case "客户端":khd = (int)sub.getValue() ;break;
					case "电子报":dzb = (int)sub.getValue() ;break;
					case "贴吧":tb = (int)sub.getValue() ;break;
					case "视频":sp = (int)sub.getValue() ;break;
					case "电视":ds = (int)sub.getValue() ;break;
					case "其他":qb = (int)sub.getValue() ;break;
				}
			}
			
			String hh = new SimpleDateFormat("HH").format(new Date(long1));
//			if(beans.size() > 10)
//			if (hh.equals("00")) {
//				wx = 0 ; wb = 0 ; lt = 0 ; xw = 0 ; bk = 0 ;zw = 0 ; khd = 0 ; dzb = 0 ; tb = 0 
//						; sp = 0 ; ds = 0;qb = 0;
//			}
			qbArray[m] = (double) qb;
			xwArray[m] = (double) xw;
			ltArray[m] = (double) lt;
			bkArray[m] = (double) bk;
			wbArray[m] = (double) wb;
			wxArray[m] = (double) wx;
			zwArray[m] = (double) zw;
			khdArray[m] = (double) khd;
			dzbArray[m] = (double) dzb;
			tbArray[m] = (double) tb;
			spArray[m] = (double) sp;
			dsArray[m] = (double) ds;
			m++;
		}
		double[][] data = {qbArray, xwArray, ltArray , bkArray , wbArray , wxArray , zwArray , khdArray , dzbArray , tbArray,
				spArray , dsArray};

//		 创建主题样式
		StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
//		 设置标题字体
		standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
		// 设置图例的字体
		standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));
		// 设置轴向的字体
		standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 10));
		// 应用主题样式
		ChartFactory.setChartTheme(standardChartTheme);
	
		CategoryDataset dataset = DatasetUtilities.createCategoryDataset(row, xAxis, data);
		JFreeChart chart = ChartFactory.createLineChart(title, null, null, dataset, PlotOrientation.VERTICAL, true,
				true, true);
		CategoryPlot plot = chart.getCategoryPlot();
		plot.setNoDataMessage("没有可供使用的数据！");
		plot.setRangeGridlinesVisible(false);
		LineAndShapeRenderer lasp = (LineAndShapeRenderer) plot.getRenderer(); 
		lasp.setSeriesPaint(11, new Color(69,114,167));
		lasp.setSeriesPaint(0, new Color(170,70,67));
		lasp.setSeriesPaint(1, new Color(69,114,167));
		lasp.setSeriesPaint(2, new Color(137,165,78));
		lasp.setSeriesPaint(3, new Color(128,105,155));
		lasp.setSeriesPaint(4, new Color(61,150,174));
		lasp.setSeriesPaint(5, new Color(219,132,61));
		lasp.setSeriesPaint(6, new Color(146,168,205));
		lasp.setSeriesPaint(7, new Color(164,125,124));
		lasp.setSeriesPaint(8, new Color(181,202,146));
		lasp.setSeriesPaint(9, new Color(187,129,78));
		lasp.setSeriesPaint(10, new Color(69,114,167));
		
		lasp.setSeriesStroke(0, new BasicStroke(2F));
		lasp.setSeriesStroke(1, new BasicStroke(2F));
		lasp.setSeriesStroke(2, new BasicStroke(2F));
		lasp.setSeriesStroke(3, new BasicStroke(2F));
		lasp.setSeriesStroke(4, new BasicStroke(2F));
		lasp.setSeriesStroke(5, new BasicStroke(2F));
		lasp.setSeriesStroke(6, new BasicStroke(2F));
		lasp.setSeriesStroke(7, new BasicStroke(2F));
		lasp.setSeriesStroke(8, new BasicStroke(2F));
		lasp.setSeriesStroke(9, new BasicStroke(2F));
		lasp.setSeriesStroke(10, new BasicStroke(2F));
		lasp.setSeriesStroke(11, new BasicStroke(2F));
		// 设置背景颜色
		plot.setBackgroundPaint(Color.WHITE);
		// 设置网格竖线颜色
		plot.setDomainGridlinePaint(Color.pink);
		// 设置网格横线颜色
		plot.setRangeGridlinePaint(Color.pink);
		if (beans.size() > 10) {
			CategoryAxis axis = plot.getDomainAxis();
			axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
		}
		// 图表位置
		String imgPath = filePath + System.currentTimeMillis() + ".png";
		File file = new File(imgPath);
		System.out.println(imgPath);
		if (!file.exists())
			file.createNewFile();
		// 保存
		if(null==chart)
			System.out.println("chart是空");
		ChartUtilities.saveChartAsPNG(file, chart, 900, 400);
		return imgPath;
	}

	public static String drawColumn(Cubes beans, String title, String filePath) throws Exception {
		// 排序
		// 创建主题样式
		StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
		// 设置标题字体
		standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
		// 设置图例的字体
		standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));
		// 设置轴向的字体
		standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));
		// 应用主题样式
		ChartFactory.setChartTheme(standardChartTheme);
		/* 柱状图 */
		DefaultCategoryDataset dataset = new DefaultCategoryDataset();
		String format = (beans.getSize() > 10) ? "M-d" : "yyyy-M-d";
		SimpleDateFormat dateFormat = new SimpleDateFormat(format);
		for (int i = (int)(beans.getSize() - 1); i >= 0; i--) {
			Cube bean = beans.getData().get(i);
			long t = Long.parseLong(bean.getKey());
			dataset.addValue(bean.getValue(), "", dateFormat.format(new Date(t)));
		}
		JFreeChart chart = ChartFactory.createBarChart(title, null, null, dataset, PlotOrientation.VERTICAL, false,
				false, false);
		CategoryPlot plot = chart.getCategoryPlot();
		plot.setNoDataMessage("没有可供使用的数据！");
		// 设置背景颜色
		plot.setBackgroundPaint(Color.WHITE);
		// 设置网格竖线颜色
		plot.setDomainGridlinePaint(Color.pink);
		// 设置网格横线颜色
		plot.setRangeGridlinePaint(Color.pink);
		if (beans.getSize() > 10) {
			CategoryAxis axis = plot.getDomainAxis();
			axis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
		}
		BarRenderer renderer = new BarRenderer();
		renderer.setMaximumBarWidth(0.1);
		renderer.setMinimumBarLength(0.1);
		renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
		renderer.setBaseItemLabelsVisible(true);
		renderer.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
				TextAnchor.BASELINE_LEFT));
		renderer.setItemLabelAnchorOffset(3D);
		renderer.setMaximumBarWidth(0.05);
		// 设置每个地区所包含的平行柱的之间距离
		plot.setRenderer(renderer);

		// 图表位置
		String imgPath = filePath + System.currentTimeMillis() + ".png";
		File file = new File(imgPath);
		if (!file.exists())
			file.createNewFile();
		// 保存
		ChartUtilities.saveChartAsPNG(file, chart, 900, 320);
		return imgPath;
	}

	public static String drawPie(List<Group> beans, String title, String filePath) throws Exception {
		// 创建主题样式
		StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
		// 设置标题字体
		standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
		// 设置图例的字体
		standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));
		// 设置轴向的字体
		standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));
		// 应用主题样式
		ChartFactory.setChartTheme(standardChartTheme);
		/* 柱状图 */
		DefaultPieDataset dataset = new DefaultPieDataset();
		int num  = beans.size()>10?10:beans.size();
		Profile profile2 = new Profile(Profile.SOURCE);
		String name ="";
		for (int i = num-1 ; i >= 0; i--) {
			Group bean = beans.get(i);
			name = profile2.getEncodeValue(bean.getKey());
			dataset.setValue(name , bean.getValue());
		}
		JFreeChart chart = ChartFactory.createPieChart(title, dataset, false, false, false);
		PiePlot plot = (PiePlot) chart.getPlot();
		plot.setSectionOutlinesVisible(false);
		plot.setNoDataMessage("没有可供使用的数据！");
		// 设置背景颜色
		plot.setBackgroundPaint(Color.WHITE);
		plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
        plot.setSectionOutlinesVisible(false);        
        plot.setNoDataMessage("没有可供使用的数据！");        
        plot.setSectionPaint(1, new Color(69,114,167));        
        plot.setSectionPaint(2, new Color(170,70,67));        
        plot.setSectionPaint(3, new Color(137,165,78));        
        plot.setSectionPaint(4, new Color(128,105,155)); 
        plot.setSectionPaint(5, new Color(61,150,174)); 
        plot.setSectionPaint(6, new Color(219,132,61)); 
        plot.setSectionPaint(7, new Color(146,168,205)); 
        plot.setSectionPaint(8, new Color(164,125,124)); 
        plot.setSectionPaint(9, new Color(181,202,146)); 
        plot.setSectionPaint(0, new Color(187,129,78));
        //值
        DecimalFormat df = new DecimalFormat("0.00%");
        NumberFormat nf = NumberFormat.getNumberInstance();
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{2}",nf,df));
		// 图表位置
		String imgPath = filePath + System.currentTimeMillis() + ".png";
		File file = new File(imgPath);
		if (!file.exists())
			file.createNewFile();
		// 保存
		ChartUtilities.saveChartAsPNG(file, chart, 400, 300);
		return imgPath;
	}
	public static String drawPie1(Groups beans, String title, String filePath) throws Exception {
		// 创建主题样式
		StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
		// 设置标题字体
		standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
		// 设置图例的字体
		standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));
		// 设置轴向的字体
		standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));
		// 应用主题样式
		ChartFactory.setChartTheme(standardChartTheme);
		/* 柱状图 */
		DefaultPieDataset dataset = new DefaultPieDataset();
		int num  = (int)(beans.getSize()>10?10:beans.getSize());
		Profile profile2 = new Profile(Profile.SOURCE);
		String name ="";
		NumberFormat nf = NumberFormat.getNumberInstance();
		nf.setMaximumFractionDigits(2);	
		for (int i = num-1 ; i >= 0; i--) {
			Group bean = beans.getData().get(i);
			System.out.println(Double.parseDouble(nf.format((double)bean.getValue()/beans.getTotal()*100)));
			dataset.setValue(bean.getKey() , Double.parseDouble(nf.format((double)bean.getValue()/beans.getTotal()*100)));
		}
		JFreeChart chart = ChartFactory.createPieChart(title, dataset, false, false, false);
		PiePlot plot = (PiePlot) chart.getPlot();
		plot.setSectionOutlinesVisible(false);
		plot.setNoDataMessage("没有可供使用的数据！");
		// 设置背景颜色
		plot.setBackgroundPaint(Color.WHITE);
		plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
        plot.setSectionOutlinesVisible(false);        
        plot.setNoDataMessage("没有可供使用的数据！");        
        plot.setSectionPaint(1, new Color(69,114,167));        
        plot.setSectionPaint(2, new Color(170,70,67));        
        plot.setSectionPaint(3, new Color(137,165,78));        
        plot.setSectionPaint(4, new Color(128,105,155)); 
        plot.setSectionPaint(5, new Color(61,150,174)); 
        plot.setSectionPaint(6, new Color(219,132,61)); 
        plot.setSectionPaint(7, new Color(146,168,205)); 
        plot.setSectionPaint(8, new Color(164,125,124)); 
        plot.setSectionPaint(9, new Color(181,202,146)); 
        plot.setSectionPaint(0, new Color(187,129,78));
        //值
       // DecimalFormat df = new DecimalFormat("0.00%");
       // NumberFormat nf = NumberFormat.getNumberInstance();
        //plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{1}"),nf,df);

        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}:{1}%"));
		// 图表位置
		String imgPath = filePath + System.currentTimeMillis() + ".png";
		File file = new File(imgPath);
		if (!file.exists())
			file.createNewFile();
		// 保存
		ChartUtilities.saveChartAsPNG(file, chart, 400, 300);
		return imgPath;
	}
//	public static void main(String[] args) throws Exception {
//		SearchFactory.init();
//		Search search = SearchFactory.getSearch();
//		search.andText(Search.TEXT, "食品");
//		long[] time = new long[2];
//		Calendar c = Calendar.getInstance();
//		c.setTime(new Date());
//		c.set(Calendar.HOUR_OF_DAY, 0);
//		c.set(Calendar.MINUTE, 0);
//		c.set(Calendar.SECOND, 0);
//		c.set(Calendar.MILLISECOND, 0);
//		c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 1);
//		time[0] = c.getTimeInMillis() - 7 * 24 * 60 * 60 * 1000l;
//		time[1] = c.getTimeInMillis() - 1l;
//		search.between(Search.TIME, time[0], time[1]);
//		search.setGroup(Search.MEDIA_TYPE);
//		GroupBeans beans = search.group();
//		String imgPath = drawPie(beans, "本周媒体类型分布图", ItextUtil.filepath(20));
//		System.out.println(imgPath);
//	}
	public static String drawColumn(Groups lastGroup, Groups thisGroup, String title, String filePath) throws Exception {
		// 排序
		System.out.println(lastGroup+"-----------------------------"+thisGroup);
		// 创建主题样式
		StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
		// 设置标题字体
		standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
		// 设置图例的字体
		standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));
		// 设置轴向的字体
		standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 10));
		// 应用主题样式
		ChartFactory.setChartTheme(standardChartTheme);
		 //柱状图 
		Profile profile = new Profile(Profile.EXCOUNT);
		int parseInt = Integer.parseInt(profile.getEncodeValue("week"));
		String row[] = {parseInt+"期" , parseInt-1+"期"};
		
		Double []thisNum = new Double[Integer.parseInt(thisGroup.getSize()+"")] , lastNum = new Double[Integer.parseInt(thisGroup.getSize()+"")];
			
		int thisPositiveNum = 0 , lastPositiveNum = 0 , thisNegativeNum = 0 , lastNegativeNum = 0
				,thisNeutralNum = 0 , lastNeutralNum = 0;
		for (int j = 0; j < thisGroup.getSize(); j++) {
			Group groupHit = thisGroup.getData().get(j);
			switch (groupHit.getKey()) {
			case "正面":thisPositiveNum =  (int)groupHit.getValue();break;
			case "负面":thisNegativeNum =  (int)groupHit.getValue();break;
			case "中性":thisNeutralNum =  (int)groupHit.getValue();break;
			}
		}
		for (int j = 0; j < lastGroup.getSize(); j++) {
			Group groupHit = lastGroup.getData().get(j);
			switch (groupHit.getKey()) {
			case "正面":lastPositiveNum =  (int)groupHit.getValue();break;
			case "负面":lastNegativeNum =  (int)groupHit.getValue();break;
			case "中性":lastNeutralNum =  (int)groupHit.getValue();break;
			}
		}
		if(thisGroup.getSize()!=0&&thisGroup.getSize()!= 0){
			thisNum[0] = (double) thisPositiveNum;		//正
			lastNum[0] = (double) lastPositiveNum;
			thisNum[2] = (double) thisNegativeNum;
			lastNum[2] = (double) lastNegativeNum;				//负
			thisNum[1] = (double) thisNeutralNum;			//中
			lastNum[1] = (double) lastNeutralNum;
		}

		
		Double data [][] = {thisNum,lastNum};
		JFreeChart chart = new BarChart().createChartBar1(title , "" , "" , row , emotion ,data);
										


		// 图表位置
		String imgPath = filePath + System.currentTimeMillis() + ".png";
		System.out.println(imgPath+"-----");
		File file = new File(imgPath);
		if (!file.exists())
			file.createNewFile();
		// 保存
		ChartUtilities.saveChartAsPNG(file, chart, 900, 320);
		return imgPath;
	}
	public static String drawLineem(List<Cube> beans, String title, String filePath) throws Exception {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		// x 轴
		int len = beans.size();
		String[] xAxis = new String[len];
//		String format;
//		try {
//			long t1 = Long.parseLong(simpleDateFormat.parse(beans.get(0).getKey()).getTime()+"");
//			long t2 = Long.parseLong(simpleDateFormat.parse(beans.get(1).getKey()).getTime()+"");
//			if ((t1 - t2) < 24 * 60 * 60 * 1000l)
//				format = "HH时";
//			else
//				format = (beans.size() > 10) ? "MM-dd" : "yyyy-MM-dd";
//		} catch (Exception e) {
//			format = "yyyy-MM-dd";
//		}
		int m = 0;

		Double[] wzwfArray = new Double[len] , zmArray = new Double [len] , fmArray = new Double [len] ;

//		// 解析结果
		for (int i = len - 1; i >= 0; i--) {
			int wzwf = 0 , zm = 0 , fm = 0 ; 
			
			xAxis[m] = beans.get(i).getKey();
			Cube bean = beans.get(i);
			for (int j = 0; j <bean.getSubs().size(); j++) {
				switch (bean.getSubs().get(j).getKey()) {
					case "中性":wzwf = (int)bean.getSubs().get(j).getValue() ;break;
					case "正面":zm = (int)bean.getSubs().get(j).getValue() ;break;
					case "负面":fm = (int)bean.getSubs().get(j).getValue() ;break;
				}
			}
			wzwfArray[m] = (double) wzwf;
			zmArray[m] = (double) zm;
			fmArray[m] = (double) fm;
			m++;
		}
		Double[][] data = { wzwfArray, zmArray , fmArray };
		// 创建主题样式
		StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
		// 设置标题字体
		standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD, 20));
		// 设置图例的字体
		standardChartTheme.setRegularFont(new Font("宋书", Font.PLAIN, 15));
		// 设置轴向的字体
		standardChartTheme.setLargeFont(new Font("宋书", Font.PLAIN, 15));
		// 应用主题样式
		ChartFactory.setChartTheme(standardChartTheme);
		// jfreechart 数据库
		//for(int jj=0;jj<row.length;jj++)
		//System.out.println("1:"+row[jj].toString());
		//for(int jj=0;jj<xAxis.length;jj++)
		//System.out.println("2:"+xAxis[jj].toString());
		//for(int jj=0;jj<data[0].length;jj++)
		//System.out.println("3:"+data[0][jj]);
		JFreeChart chart = new LineChart().createChartLine1(title , "" , "" ,emotion , xAxis ,data);
		
		// 图表位置
		String imgPath = filePath + System.currentTimeMillis() + ".png";
		System.out.println("月报正负面趋势的图片"+imgPath);
		File file = new File(imgPath);
		if (!file.exists())
			file.createNewFile();
		// 保存
		ChartUtilities.saveChartAsPNG(file, chart, 900, 320);
		return imgPath;
	}
}
